package com.ruoyi.web.controller.teacher.education;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.teacher.UserEducation;
import com.ruoyi.system.service.teacher.IUserEducationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教育经历Controller
 * 
 * @author ruoyi
 * @date 2025-07-24
 */
@RestController
@RequestMapping("/teacher/education")
public class UserEducationController extends BaseController
{
    @Autowired
    private IUserEducationService userEducationService;

    /**
     * 查询教育经历列表
     */
   @PreAuthorize("@ss.hasPermi('system:education:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserEducation userEducation)
    {
        startPage();
        List<UserEducation> list = userEducationService.selectUserEducationList(userEducation);
        return getDataTable(list);
    }

    /**
     * 导出教育经历列表
     */
    @PreAuthorize("@ss.hasPermi('system:education:export')")
    @Log(title = "教育经历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserEducation userEducation)
    {
        List<UserEducation> list = userEducationService.selectUserEducationList(userEducation);
        ExcelUtil<UserEducation> util = new ExcelUtil<UserEducation>(UserEducation.class);
        util.exportExcel(response, list, "教育经历数据");
    }

    /**
     * 获取教育经历详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:education:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userEducationService.selectUserEducationById(id));
    }

    /**
     * 新增教育经历
     */
    @PreAuthorize("@ss.hasPermi('system:education:add')")
    @Log(title = "教育经历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserEducation userEducation)
    {
        return toAjax(userEducationService.insertUserEducation(userEducation));
    }

    /**
     * 修改教育经历
     */
    @PreAuthorize("@ss.hasPermi('system:education:edit')")
    @Log(title = "教育经历", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserEducation userEducation)
    {
        return toAjax(userEducationService.updateUserEducation(userEducation));
    }

    /**
     * 删除教育经历
     */
    @PreAuthorize("@ss.hasPermi('system:education:remove')")
    @Log(title = "教育经历", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userEducationService.deleteUserEducationByIds(ids));
    }

    /**
     * 根据用户id查询教育经历
     */
    @GetMapping("/getEducationByUserId/{userId}")
    public AjaxResult getEducationByUserId(@PathVariable("userId") Long userId)
    {
        List<UserEducation> list = userEducationService.getEducationByUserId(userId);
        return     AjaxResult.success(list);
    }
    /**
     * 删除教育经历信息
     */
    @DeleteMapping("/delEducationById/{id}")
    public AjaxResult delEducationById(@PathVariable("id") Long id)
    {
        return toAjax(userEducationService.deleteUserEducationById(id));
    }

    /**
     * 新增教育经历
     */
    @PostMapping("/addEducation")
    public AjaxResult addEducation(@RequestBody UserEducation userEducation)
    {
        return toAjax(userEducationService.insertUserEducation(userEducation));
    }
}
